Catch read() err
authorJeroen van der Heijden <jeroen@cesbit.com>
Wed, 13 Apr 2022 11:14:41 +0000 (13:14 +0200)
committerJeroen van der Heijden <jeroen@cesbit.com>
Wed, 13 Apr 2022 11:14:41 +0000 (13:14 +0200)
main.c

diff --git a/main.c b/main.c
index 80f190750ad96f70df8154ad8f206b358aa9cb92..cd69a00fa953b2f466c077a4242998a0443a014d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -32,20 +32,6 @@ int main(int argc, char * argv[])
     /* set local to LC_ALL and C to force a period over comma for float */
     (void) setlocale(LC_ALL, "C");
 
-    /* initialize random */
-    seed = 0;
-    fd = open("/dev/urandom", O_RDONLY);
-
-    if ( fd == -1 ) {
-        log_info("Could not open /dev/urandom");
-        return 1;
-    }
-
-    read(fd, &seed, sizeof(int));
-    close(fd);
-
-    srand(seed);
-
     /* set threadpool size to 8 (default=4) */
     putenv("UV_THREADPOOL_SIZE=8");
 
@@ -59,6 +45,18 @@ int main(int argc, char * argv[])
     /* setup logger, this must be done before logging the first line */
     siri_setup_logger();
 
+    /* initialize random */
+    seed = 0;
+    fd = open("/dev/urandom", O_RDONLY);
+    if (fd == -1 || read(fd, &seed, sizeof(int)) == -1)
+    {
+        log_error("Could not open /dev/urandom");
+        return 1;
+    }
+
+    (void) close(fd);
+    srand(seed);
+
     /* initialize points dictionary */
     siridb_points_init();